package main

import (
	"flag"
	"fmt"
	_ "lao-a/models"
	"lao-a/models/sync"
	_ "lao-a/routers"
	"os"
	"strings"

	"github.com/astaxie/beego"
)

var syncDB = flag.Bool("sync", false, "同步表或者数据入库")
var syncTable = flag.String("table", "all", "同步表名称, 多表使用半角逗号连接, all(default)-全部表, no-不同步表")
var syncData = flag.String("data", "no", "同步数据入库,暂时只支持内置数据入库, all-所有内置数据, no(default)-不同步数据")

func main() {
	flag.Parse()

	if *syncDB {
		if *syncTable != "no" {
			tabs := strings.Split(*syncTable, ",")
			for _, tab := range tabs {
				sync.Table(tab)
			}

			fmt.Fprintln(os.Stdout, "同步表结构完成! ")
		}

		if *syncData != "no" {
			if err := sync.Data(); err != nil {
				fmt.Fprintln(os.Stderr, "同步数据失败: "+err.Error())
				return
			}
		}

		return
	}

	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.Run()

}
